package ltd.hanamaki.shopping;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

public class EcShopShoppingTest {

  private WebDriver driver;
  @BeforeClass
  public void setUp() {
    System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void ecShopShopping() {
    driver.get("http://192.168.0.142/ecshop/");
    driver.manage().window().maximize();
    driver.findElement(By.cssSelector("#ECS_MEMBERZONE > a:nth-child(2) > img")).click();
    driver.findElement(By.name("username")).sendKeys("jojo2");
    driver.findElement(By.name("password")).sendKeys("111111");
    driver.findElement(By.name("submit")).click();
    driver.findElement(By.cssSelector("#show_best_area > .goodsItem:nth-child(1) .goodsimg")).click();
    driver.findElement(By.cssSelector(".padd > a:nth-child(1) > img")).click();
    driver.findElement(By.cssSelector("td:nth-child(2) img")).click();
    driver.findElement(By.id("selProvinces_0")).click();
    {
      WebElement dropdown = driver.findElement(By.id("selProvinces_0"));
      dropdown.findElement(By.xpath("//option[. = '上海']")).click();
    }
    driver.findElement(By.xpath("/html/body/div[7]/form/div/table/tbody/tr[1]/td[2]/select[3]/option[2]")).click();
    {
      WebElement dropdown = driver.findElement(By.id("selDistricts_0"));
      dropdown.findElement(By.xpath("//option[. = '静安区']")).click();
    }
    driver.findElement(By.cssSelector("#selDistricts_0 > option:nth-child(9)")).click();
    driver.findElement(By.id("consignee_0")).click();
    driver.findElement(By.id("consignee_0")).sendKeys("31321");
    driver.findElement(By.id("address_0")).click();
    driver.findElement(By.id("address_0")).sendKeys("31321");
    driver.findElement(By.id("tel_0")).click();
    driver.findElement(By.id("tel_0")).sendKeys("32131");
    driver.findElement(By.name("Submit")).click();
    driver.findElement(By.name("shipping")).click();
    {
      WebElement element = driver.findElement(By.name("shipping"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    {
      WebElement element = driver.findElement(By.tagName("body"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element, 0, 0).perform();
    }
    driver.findElement(By.cssSelector("#paymentTable tr:nth-child(3) input")).click();
    {
      WebElement element = driver.findElement(By.cssSelector("#paymentTable tr:nth-child(3) input"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element).perform();
    }
    {
      WebElement element = driver.findElement(By.tagName("body"));
      Actions builder = new Actions(driver);
      builder.moveToElement(element, 0, 0).perform();
    }
    driver.findElement(By.cssSelector("div > input:nth-child(1)")).click();

  }

  @AfterClass
  public void tearDown() {
//    driver.quit();
  }
}
